package com.tally.server.aspect;

import com.tally.server.utils.IpUtil;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: sy
 * @Date: 2020/12/22 17:09
 * @Description: 获取客户端ip切面
 */
@Aspect
@Component
public class IpAspect {
    private static final Logger logger = LoggerFactory.getLogger(IpAspect.class);

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private HttpServletRequest request;

    @Pointcut("execution(* com.tally.*.controller..*.*(..))")
    public void ipAspect(){}

    @Before("ipAspect()")
    public void processIp(){
        String ipAddress = IpUtil.getIpAddress(request);
        logger.info("ip地址为：{}",ipAddress);
    }
}
